load("@rules_proto//proto:defs.bzl", "proto_library")
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")

go_library(
    name = "persistedsqlstats",
    srcs = [
        "cluster_settings.go",
        "combined_iterator.go",
        "compaction_exec.go",
        "compaction_scheduling.go",
        "controller.go",
        "flush.go",
        "mem_iterator.go",
        "provider.go",
        "scheduled_job_monitor.go",
        "stmt_reader.go",
        "txn_reader.go",
    ],
    embed = [":persistedsqlstats_go_proto"],
    importpath = "github.com/cockroachdb/cockroach/pkg/sql/sqlstats/persistedsqlstats",
    visibility = ["//visibility:public"],
    deps = [
        "//pkg/base",
        "//pkg/jobs",
        "//pkg/jobs/jobspb",
        "//pkg/scheduledjobs",
        "//pkg/security/username",
        "//pkg/server/serverpb",
        "//pkg/settings",
        "//pkg/settings/cluster",
        "//pkg/sql/appstatspb",
        "//pkg/sql/catalog/systemschema",
        "//pkg/sql/isql",
        "//pkg/sql/sem/tree",
        "//pkg/sql/sessiondata",
        "//pkg/sql/sqlstats",
        "//pkg/sql/sqlstats/persistedsqlstats/sqlstatsutil",
        "//pkg/sql/sqlstats/sslocal",
        "//pkg/sql/types",
        "//pkg/util",
        "//pkg/util/admission/admissionpb",
        "//pkg/util/log",
        "//pkg/util/metric",
        "//pkg/util/mon",
        "//pkg/util/retry",
        "//pkg/util/stop",
        "//pkg/util/syncutil",
        "//pkg/util/timeutil",
        "//pkg/util/uuid",
        "@com_github_cockroachdb_errors//:errors",
        "@com_github_cockroachdb_redact//:redact",
        "@com_github_gogo_protobuf//types",
        "@com_github_robfig_cron_v3//:cron",
    ],
)

go_test(
    name = "persistedsqlstats_test",
    srcs = [
        "bench_test.go",
        "compaction_test.go",
        "controller_test.go",
        "datadriven_test.go",
        "flush_test.go",
        "main_test.go",
        "reader_test.go",
        "scheduled_sql_stats_compaction_test.go",
    ],
    data = glob(["testdata/**"]),
    exec_properties = select({
        "//build/toolchains:is_heavy": {"test.Pool": "heavy"},
        "//conditions:default": {"test.Pool": "default"},
    }),
    shard_count = 16,
    deps = [
        ":persistedsqlstats",
        "//pkg/base",
        "//pkg/jobs",
        "//pkg/jobs/jobspb",
        "//pkg/jobs/jobstest",
        "//pkg/keys",
        "//pkg/kv/kvpb",
        "//pkg/kv/kvserver",
        "//pkg/roachpb",
        "//pkg/scheduledjobs",
        "//pkg/security/securityassets",
        "//pkg/security/securitytest",
        "//pkg/security/username",
        "//pkg/server",
        "//pkg/server/serverpb",
        "//pkg/sql",
        "//pkg/sql/appstatspb",
        "//pkg/sql/catalog",
        "//pkg/sql/catalog/systemschema",
        "//pkg/sql/isql",
        "//pkg/sql/sem/catconstants",
        "//pkg/sql/sem/tree",
        "//pkg/sql/sessiondata",
        "//pkg/sql/sqlstats",
        "//pkg/sql/sqlstats/persistedsqlstats/sqlstatstestutil",
        "//pkg/sql/sqlstats/ssmemstorage",
        "//pkg/testutils",
        "//pkg/testutils/datapathutils",
        "//pkg/testutils/serverutils",
        "//pkg/testutils/skip",
        "//pkg/testutils/sqlutils",
        "//pkg/testutils/testcluster",
        "//pkg/util/encoding",
        "//pkg/util/leaktest",
        "//pkg/util/log",
        "//pkg/util/metric",
        "//pkg/util/randutil",
        "//pkg/util/stop",
        "//pkg/util/syncutil",
        "//pkg/util/timeutil",
        "//pkg/util/uuid",
        "@com_github_cockroachdb_datadriven//:datadriven",
        "@com_github_cockroachdb_errors//:errors",
        "@com_github_stretchr_testify//require",
    ],
)

proto_library(
    name = "persistedsqlstats_proto",
    srcs = ["sql_stats_compact.proto"],
    strip_import_prefix = "/pkg",
    visibility = ["//visibility:public"],
)

go_proto_library(
    name = "persistedsqlstats_go_proto",
    compilers = ["//pkg/cmd/protoc-gen-gogoroach:protoc-gen-gogoroach_compiler"],
    importpath = "github.com/cockroachdb/cockroach/pkg/sql/sqlstats/persistedsqlstats",
    proto = ":persistedsqlstats_proto",
    visibility = ["//visibility:public"],
)
